extends Node2D

var run_index = 0
var click_index = 0

var animation_times = 0
# 本月属性增加
var this_month = {
	"shenli":0,
	"tili":0,
	"zhili":0,
	"qizhi":0,
	"pilao":0,
	"coin":0
}
func _ready():
	randomize()
	print_debug("场景切换完成，要执行的事情 ",Global.week_anpai)
	match Global.week_anpai[0]:
		"magic":
			$AnimatedSprite.play("magic_class")
			this_month["shenli"] += randi() %20
			add_pilao()
			change_class_icon("magic")
		"gedou":
			$AnimatedSprite.play("gedou_class")
			this_month["tili"] += randi() %20
			add_pilao()
			change_class_icon("gedou")
		"wenxue":
			$AnimatedSprite.play("wenxue_class")
			this_month["zhili"] += randi()%20
			add_pilao()
			change_class_icon("wenxue")
		"music":
			$AnimatedSprite.play("music_class")
			this_month["qizhi"] += randi()%20
			add_pilao()
			change_class_icon("music")
		"work":
			$AnimatedSprite.play("work")
			this_month["coin"] += 18
		"reset":
			$AnimatedSprite.play("reset")
			jianshao_pilao()
	#$DialogAndInfo.text = "老师：今天的练习就要开始喽"
func change_class_icon(type):
	match type:
		"magic":
			$class_tag.texture = Global.magic_class_icon
		"gedou":
			$class_tag.texture = Global.gedou_class_icon
		"music":
			$class_tag.texture = Global.music_class_icon
		"reset":
			$class_tag.texture = Global.music_class_icon
	pass
# warning-ignore:unused_argument
func _input(event):
#	if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
#		$DialogAndInfo.text = ""
#		if Global.week_anpai[run_index] == "magic":
#			$AnimatedSprite.play("magic_class")
	pass


func _on_AnimatedSprite_animation_finished():
	if run_index < 3:
		run_index +=1
		match Global.week_anpai[run_index]:
			"magic":
				$AnimatedSprite.play("magic_class")
				this_month["shenli"] += randi() %20
				add_pilao()
				change_class_icon("magic")
			"gedou":
				$AnimatedSprite.play("gedou_class")
				this_month["tili"] += randi() %20
				add_pilao()
				change_class_icon("gedou")
			"wenxue":
				$AnimatedSprite.play("wenxue_class")
				this_month["zhili"] += randi()%20
				add_pilao()
				change_class_icon("wenxue")
			"music":
				$AnimatedSprite.play("music_class")
				this_month["qizhi"] += randi()%20
				add_pilao()
				change_class_icon("music")
			"work":
				$AnimatedSprite.play("work")
				this_month["coin"] += 18
				add_pilao()
			"reset":
				$AnimatedSprite.play("reset")
				jianshao_pilao()
	elif run_index == 3:
			$AnimatedSprite.stop()
			$DialogAndInfo.text = "本月总结" + "神力" + str(this_month["shenli"]) + "体力" + str(this_month["tili"]) + "气质" + str(this_month["qizhi"]) + "智力"  +str(this_month["zhili"]) + "疲劳" + str(Global.data["pilao"]) + "金币" + str(this_month["coin"])
			$Close.show()
	pass
func jianshao_pilao():
	if Global.data["pilao"]> 0:
		Global.data["pilao"] -= randi() %20
		if Global.data["pilao"] <= 0:
			Global.data["pilao"] = 0
func add_pilao():
#	this_month["pilao"] += randi() %20
	Global.data["pilao"] += randi() %20
	pass
func _on_Close_pressed():
	#保存Global.data游戏存档
	Global.week1 = null
	Global.week2 = null
	Global.week3 = null 
	Global.week4 = null
	Global.week_anpai.clear()
	if Global.data.month < 12:
		Global.data.month += 1
	elif Global.data.month == 12:
		Global.data.month = 1
		if Global.data.year <6:
			Global.data.year +=1
			Global.data.age += 1
		elif Global.data.year == 6:
			Global.data["end"] = true
			get_tree().change_scene("res://scene/EndCG.tscn")
	Global.data.shenli += this_month["shenli"]
	Global.data.qizhi += this_month["qizhi"]
	Global.data.zhili += this_month["zhili"]
	
	Global.data.coin += this_month["coin"]
	Global.data.tili += this_month["tili"]
	if Global.data["shenli"] >= 100 and Global.data["shenli"] < 200:
		Global.data["tixing"] = "C级巨人"
	elif Global.data["shenli"] >= 200 and Global.data["shenli"] <300:
		Global.data["tixing"] = "B级巨人"
	elif Global.data["shenli"] >= 300:
		Global.data["tixing"] = "S级巨人"
#	if Global.data["year"] == 6 and Global.data["month"] == 12:
#		Global.data["end"] = true
#		get_tree().change_scene("res://scene/EndCG.tscn")
	Global.save()
#	print_debug("清除上月",Global.week_anpai)
	get_tree().change_scene("res://scene/Game.tscn")
	pass # Replace with function body.
	
#	for anpai in Global.week_anpai:
#		if anpai == "magic":
#			$DialogAndInfo.text = "老师：今天的练习就要开始喽"
#			$AnimatedSprite.play("magic_class")
#		elif anpai == "gedou":
#			$DialogAndInfo.text = "老师：不要废话，快练习"
#			$AnimatedSprite.play("gedou_class")
#		elif anpai == "wenxue":
#			$DialogAndInfo.text = "老师：要准备好学习新的文法了"
#			$AnimatedSprite.play("wenxue_class")
#		elif anpai == "music":
#			$DialogAndInfo.text = "老师：听公园里的精灵正在唱歌呢"
#			$AnimatedSprite.play("music_class")
